package com.anlen.experimentfour;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;

public class FileService {
	//保存信息
	public void saveInfo(Context context,String name,String password){
		File file=new File(context.getFilesDir(),"info.ini");
		try {
			FileOutputStream fos=new FileOutputStream(file);
			fos.write((name+"##"+password).getBytes());
			fos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	//获得文件信息
	public static Map<String,String> getinfo(Context context){
		File file=new File(context.getFilesDir(),"info.ini");
		FileInputStream fis;
		try {
			fis = new FileInputStream(file);
			BufferedReader br=new BufferedReader(new InputStreamReader(fis));
			
			String str=br.readLine();
			String[] info=str.split("##");
			Map<String, String> map=new HashMap<String, String>();
			map.put("name", info[0]);
			map.put("password", info[1]);
			
			br.close();
			fis.close();
			return map;
			
		} catch (Exception e) {
			e.printStackTrace();	
			return null;
		}
		
		
	
	}
	
}
